package com.gargi.crimepatrol.network;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

public abstract class Parser
extends DefaultHandler {

private StringBuffer chars = new StringBuffer();

/**
 * Event handler for the start of an XML element. 
 * Clears the content string buffer so that a new string can be stored.
 * @see DefaultHandler#startElement(java.lang.String, java.lang.String, 
 * java.lang.String, org.xml.sax.Attributes) 
 */
public void startElement(String uri, String localName, String qName,
    Attributes attributes) {
    chars = new StringBuffer();
}

/**
 * Character callback for content characters. Data is appended to the
 * string buffer.
 * @see DefaultHandler#characters(char[], int, int) 
 */
public final void characters(char[] ch, int start, int length) {
    chars.append(ch, start, length);
}

/**
 * Retrieves the last content string and clears the string buffer.
 * @return content string
 */
protected final String getChars() {
    // For some reason there is some extra whitespace around 
    // the characters sometimes. Trim those out.
    String c = chars.toString().trim();
    chars = new StringBuffer();
    return c;
}
}
